package com.hiwan.framework.servlet.tags;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hiwan.platform.util.BeanUtils;
import com.hiwan.platform.util.ReflectHelper;
import com.hiwan.platform.util.StackTraceUtil;
import com.hiwan.system.cache.SysCacheService;
import com.hiwan.system.pojo.ParameterInfo;

public class ParameterTag extends TagSupport {
	private static final long serialVersionUID = 429589404960812803L;
	private JspWriter out;
	private String paramType;
	private String orgId;
	private String paramKey;
	private String paramNum;

	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public int doStartTag() throws JspException {
		out = this.pageContext.getOut();

		SysCacheService sysCacheService = BeanUtils.getBean("sysCacheService",
				SysCacheService.class);
		ParameterInfo paraInfo = sysCacheService.getSysParameter(paramType,
				orgId, paramKey);

		try {
			if (paraInfo == null) {
				out.print("");
			} else {
				Object value = ReflectHelper.getValueByFieldName(paraInfo,
						paramNum);
				out.print(value == null ? "" : value);
			}
		} catch (Exception e) {
			logger.error(StackTraceUtil.getStackTrace(e));
		}
		return TagSupport.EVAL_PAGE;
	}

	public JspWriter getOut() {
		return out;
	}

	public void setOut(JspWriter out) {
		this.out = out;
	}

	public String getParamType() {
		return paramType;
	}

	public void setParamType(String paramType) {
		this.paramType = paramType;
	}

	public String getOrgId() {
		return orgId;
	}

	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}

	public String getParamKey() {
		return paramKey;
	}

	public void setParamKey(String paramKey) {
		this.paramKey = paramKey;
	}

	public String getParamNum() {
		return paramNum;
	}

	public void setParamNum(String paramNum) {
		this.paramNum = paramNum;
	}
}
